package com.zxcrm.web.controller.zxcrm;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zxcrm.common.annotation.Log;
import com.zxcrm.common.core.controller.BaseController;
import com.zxcrm.common.core.domain.AjaxResult;
import com.zxcrm.common.enums.BusinessType;
import com.zxcrm.zxcrm.domain.ZxcrmBusinessOpportunity;
import com.zxcrm.zxcrm.service.IZxcrmBusinessOpportunityService;
import com.zxcrm.common.utils.poi.ExcelUtil;
import com.zxcrm.common.core.page.TableDataInfo;

/**
 * 商机Controller
 * 
 * @author xu
 * @date 2025-07-08
 */
@RestController
@RequestMapping("/zxcrm/businessOpportunity")
public class ZxcrmBusinessOpportunityController extends BaseController
{
    @Autowired
    private IZxcrmBusinessOpportunityService zxcrmBusinessOpportunityService;

    /**
     * 查询商机列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:businessOpportunity:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZxcrmBusinessOpportunity zxcrmBusinessOpportunity)
    {
        startPage();
        List<ZxcrmBusinessOpportunity> list = zxcrmBusinessOpportunityService.selectZxcrmBusinessOpportunityList(zxcrmBusinessOpportunity);
        return getDataTable(list);
    }


    /**
     * 导出商机列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:businessOpportunity:export')")
    @Log(title = "商机", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZxcrmBusinessOpportunity zxcrmBusinessOpportunity)
    {
        List<ZxcrmBusinessOpportunity> list = zxcrmBusinessOpportunityService.selectZxcrmBusinessOpportunityList(zxcrmBusinessOpportunity);
        ExcelUtil<ZxcrmBusinessOpportunity> util = new ExcelUtil<ZxcrmBusinessOpportunity>(ZxcrmBusinessOpportunity.class);
        util.exportExcel(response, list, "商机数据");
    }

    /**
     * 获取商机详细信息
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:businessOpportunity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zxcrmBusinessOpportunityService.selectZxcrmBusinessOpportunityById(id));
    }

    /**
     * 新增商机
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:businessOpportunity:add')")
    @Log(title = "商机", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZxcrmBusinessOpportunity zxcrmBusinessOpportunity)
    {
        return toAjax(zxcrmBusinessOpportunityService.insertZxcrmBusinessOpportunity(zxcrmBusinessOpportunity));
    }

    /**
     * 修改商机
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:businessOpportunity:edit')")
    @Log(title = "商机", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZxcrmBusinessOpportunity zxcrmBusinessOpportunity)
    {
        return toAjax(zxcrmBusinessOpportunityService.updateZxcrmBusinessOpportunity(zxcrmBusinessOpportunity));
    }

    /**
     * 删除商机
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:businessOpportunity:remove')")
    @Log(title = "商机", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zxcrmBusinessOpportunityService.deleteZxcrmBusinessOpportunityByIds(ids));
    }
}
